<?php 
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;

	class SummaryController extends AdminBaseController
	{
			
		/*园区房间列表页*/	
		public function index(){
	// 		echo session('role_id').',';
	// echo session('incubator_id');
	// 			exit;
			$condition='';
			if(session('incubator_id')){
				$condition['id']=session('incubator_id');
			}
			$incubator_list=db('incubator')->where(array('status'=>1))->where($condition)->field('id,incubator_name')->select();
			$stime = $this->request->param('start_time');
			$etime = $this->request->param('end_time');
			$incubator_id = $this->request->param('incubator_id',0);
			$where=array();
			$wheres=array();
			$wheresta=array();
			if ($stime) {
				$where['create_time'] = array('gt',$stime);
				$wheres['create_time'] = array('gt',$stime);
				$wheresta['add_time'] = array('gt',$stime);
			}
			if ($etime) {
				$where['create_time'] = array('lt',$etime);
				$wheres['create_time'] = array('lt',$etime);
				$wheresta['add_time'] = array('lt',$etime);
			}
			$this->assign('incubator_id','');

			if ($incubator_id) {
				$where['incubator_id'] = $incubator_id;
				$wheres['r.incubator_id'] = $incubator_id;
				$wheresta['incubator_id'] = $incubator_id;
				$this->assign('incubator_id',$incubator_id);
				// $wheres['create_time'] = array('lt',$etime);
			}
			
			$incubator_id = $this->request->param('incubator_id',0);
			if ($incubator_id) {
				$where['incubator_id'] = $incubator_id;
				$wheres['r.incubator_id'] = $incubator_id;
				$wheresta['incubator_id'] = $incubator_id;
				//$this->assign('incubator_id',$incubator_id);
				// $wheres['create_time'] = array('lt',$etime);
			}
			if(session('incubator_id')){
				// echo session('incubator_id');
				// exit;
				$where['incubator_id']=session('incubator_id');
				$wheres['r.incubator_id']=session('incubator_id');
				$wheresta['incubator_id'] =session('incubator_id');
			}
			/*押金总额*/
			// echo 22222;
			// exit;
			$data['total_deposit']=db('spaceOrder')->where($where)->sum('deposit_price');
			// echo $data['total_deposit'];
			// echo 	db('spaceOrder')->getLastSql();
			// exit;
			/*yi zhi fu de 租金总额*/
			// $data['sum_price']=db('spaceOrder')->where($where)->sum('sum_price');
			
			/*总入孵企业*/
			$data['total_customer']=db('customer')->where(array('status'=>1,'stage'=>4))->where($where)->count();
			/*总成交面积*/
		
			$data['total_area']=db('spaceOrder')->alias('r')->where(array('r.status'=>1))->where($wheres)->join('station s','r.space_id=s.id')->sum('s.covered_area');	
			$now_time=time();
			$where_con="stime <= $now_time and etime >= $now_time";
			$data['sum_price']=db('rent')->where($where)->where($where_con)->sum('round_price');
			// echo db('rent')->getLastSql();
			// exit;
			$data['actual_total_rent']=	db('rent')->where(array('status'=>2))->where($where)->where($where_con)->sum('round_price');
			// echo db('rent')->getLastSql();
			// exit;
			/*实收总额*/
			//$data['actual_total_rent']=db('rent')->where(array('status'=>2))->where($where)->sum('round_price');
			/*应收总额*/
		
			$data['total_rent']=db('rent')->where($where)->sum('round_price');
			
			/*总订单数*/
			$data['total_order']=db('spaceOrder')->where($where)->where('status',1)->count();
			// echo db('spaceOrder')->getLastSql();
			// exit;
			/*园区总面积*/
		
			//$data['park_space_area']=db("station")->where(array('incubator_type'=>1,'type'=>1,'status'=>1))->where($where)->sum("covered_area");
			/*空间总面积*/
		
			//exit;
	// echo 2222;
	// 	exit;
			$data['park_space_area']=db("station")->where(array('incubator_type'=>1,'status'=>1))->where($wheresta)->sum("covered_area");
			/*园区总办公室数*/

			$data['park_space_num']=db("station")->where(array('incubator_type'=>1,'status'=>1))->where($wheresta)->count();
		// 	echo Db::name('station')->getLastSql();
		// exit;
			/*空间总办公室数*/
			$data['space_num']=db("station")->where(array('incubator_type'=>2,'type'=>1,'status'=>1))->where($wheresta)->count();
			/*总工位数*/
			
			$data['station_num']=db("station")->where(array('type'=>2,'status'=>1))->where($wheresta)->count();
	
			//exit;
			/*总场地个数*/
			$data['site_num']=db("site")->where(array('status'=>1))->where($wheresta)->count();
			/*总客户数*/	
			$data['customer_num']=db("customer")->where(array('status'=>1))->where($wheresta)->count();
			/*总入孵化企业数*/	
			$data['company_num']=db("customer")->where(array('status'=>1,'follow_stage'=>5))->where($wheresta)->count();
			$this->assign('incubator_list',$incubator_list);
			$this->assign('start_time',$stime);	
			$this->assign('end_time',$etime);	
			$this->assign("list", $data);

			return $this->fetch();
			//return info_back($data,'返回成功',true);
		}
		/*运营统计*/
		function  operationSum(){
			/*押金总额*/
			$data['total_deposit']=db('spaceOrder')->sum('deposit_price');

			/*租金总额*/
			$data['total_deposit']=db('spaceOrder')->sum('sum_price');
			/*总入孵企业*/
			$data['total_customer']=db('customer')->where('status',1)->count();
			/*总成交面积*/
		
			$data['total_area']=db('spaceOrder')->alias('r')->where(array('r.status'=>1))->join('station s','r.space_id=s.id')->sum('s.covered_area');	

			/*实收总额*/
			$data['actual_total_rent']=db('rent')->where(array('status'=>2))->sum('round_price');
			/*应收总额*/
			
			$data['total_rent']=db('rent')->sum('round_price');
			/*总订单数*/
			$data['total_order']=db('spaceOrder')->count();
			return info_back($data,'返回成功',true);

		}
        /*客户领域*/
		function customerFields(){
			$where=array();
			$sum='';
			if(session('incubator_id')){
				$where['incubator_id']=session('incubator_id');
				$wheres['r.incubator_id']=session('incubator_id');
			}
			$incubator_id = $this->request->param('incubator_id',0);
			if ($incubator_id) {
				$where['incubator_id'] = $incubator_id;
				$wheres['r.incubator_id'] = $incubator_id;
				//$this->assign('incubator_id',$incubator_id);
				// $wheres['create_time'] = array('lt',$etime);
			}
			$stime = $this->request->param('start_time');
			$etime = $this->request->param('end_time');
			if ($stime) {
				$where['create_time'] = array('gt',$stime);
				$wheres['create_time'] = array('gt',$stime);
			}
			if ($etime) {
				$where['create_time'] = array('lt',$etime);
				$wheres['create_time'] = array('lt',$etime);
			}
			$fields=db('customer')->field('field')->where('status',1)->where($where)->select();
			// echo db('customer')->getLastSql();
			// exit;
			$arr=array();
			foreach ($fields as $key => $value) {
				if(empty($arr[$value['field']]['count'])){
					$arr[$value['field']]['count']=1;
					$arr[$value['field']]['name']=get_cate_name(6,$value['field']);
				}else{
					$arr[$value['field']]['count']++;
				}
				// $arr[$value['field']]=$arr[$value['field']]+1;
				// echo $value['field'];
				// $arr[$value['field']];
			}
			foreach ($arr as $k => $v) {
				$sum+=$v['count'];
			}
			foreach ($arr as $k1 => $v1) {
				$arr[$k1]['name']=$v1['name']. '('.round($v1['count']/$sum*100,2).'%)' ;
			}
			return json($arr);
		}
		 /*客户领域*/
		function customerStage(){
			$where=array();
			if(session('incubator_id')){
				$where['incubator_id']=session('incubator_id');
				$wheres['r.incubator_id']=session('incubator_id');
			}
			$incubator_id = $this->request->param('incubator_id',0);
			if ($incubator_id) {
				$where['incubator_id'] = $incubator_id;
				$wheres['r.incubator_id'] = $incubator_id;
				//$this->assign('incubator_id',$incubator_id);
				// $wheres['create_time'] = array('lt',$etime);
			}
			$stime = $this->request->param('start_time');
			$etime = $this->request->param('end_time');
			if ($stime) {
				$where['create_time'] = array('gt',$stime);
				$wheres['create_time'] = array('gt',$stime);
			}
			if ($etime) {
				$where['create_time'] = array('lt',$etime);
				$wheres['create_time'] = array('lt',$etime);
			}
			$stages=db('customer')->field('stage')->where('status',1)->where($where)->select();
			// echo db('customer')->getLastSql();
			// exit;
			$arr=array();
			foreach ($stages as $key => $value) {
				if(empty($arr[$value['stage']]['count'])){
					$arr[$value['stage']]['count']=1;
					// switch ($value['stage']) {
					// 	case 0:
					// 	$arr[$value['stage']]['name']='未跟进';
					// 	break;
					// 	case 1:
					// 	$arr[$value['stage']]['name']='初步洽谈';
					// 	break;
					// 	case 2:
					// 	$arr[$value['stage']]['name']='需求确认';
					// 	break;
					// 	case 3:
					// 	$arr[$value['stage']]['name']='意向确认';
					// 	break;
					// 	case 4:
					// 	$arr[$value['stage']]['name']='入孵签订';
					// 	break;
					// 	case 5:
					// 	$arr[$value['stage']]['name']='客户流失';
					// 	break;

						
					// 	default:
					// 		$arr[$value['stage']]['name']='未跟进';
					// 		break;
					// }

					$arr[$value['stage']]['name']=get_cate_name(10,$value['stage']);
				}else{
					$arr[$value['stage']]['count']++;
				}
				// $arr[$value['field']]=$arr[$value['field']]+1;
				// echo $value['field'];
				// $arr[$value['field']];
			}
			$sum='';
			foreach ($arr as $k => $v) {
				$sum+=$v['count'];
			}
			foreach ($arr as $k1 => $v1) {
				$arr[$k1]['name']=$v1['name']. '('.round($v1['count']/$sum*100,2).'%)' ;
			}
			return json($arr);
		}
		// 园区租占比例
		function rentRate(){
			$where=array();
			if(session('incubator_id')){
				$where['incubator_id']=session('incubator_id');
				$wheres['r.incubator_id']=session('incubator_id');
			}
			$incubator_id = $this->request->param('incubator_id',0);
			if ($incubator_id) {
				$where['incubator_id'] = $incubator_id;
				$wheres['r.incubator_id'] = $incubator_id;
				//$this->assign('incubator_id',$incubator_id);
				// $wheres['create_time'] = array('lt',$etime);
			}
			$stime = $this->request->param('start_time');
			$etime = $this->request->param('end_time');
			if ($stime) {
				$where['add_time'] = array('gt',$stime);
				$wheres['add_time'] = array('gt',$stime);
			}
			if ($etime) {
				$where['add_time'] = array('lt',$etime);
				$wheres['add_time'] = array('lt',$etime);
			}
			$has_rent=db('station')->where(array('incubator_type'=>1,'is_rent'=>1))->where($where)->count();
			$sum=db('station')->where(array('incubator_type'=>1))->where($where)->count();
			if($sum==0){
				return '';
			}
			// echo db('station')->getLastSql();
			// exit;
			// var_dump($sum);
			// exit;
			$arr['has_rent']['count']=$has_rent;
			$arr['has_rent']['name']='已租';
			$arr['no_rent']['count']=$sum-$has_rent;
			$arr['no_rent']['name']='未租';
			$sum='';
			foreach ($arr as $k => $v) {
				$sum+=$v['count'];
			}
			foreach ($arr as $k1 => $v1) {
				$arr[$k1]['name']=$v1['name']. '('.round($v1['count']/$sum*100,2).'%)' ;
			}

			return json($arr);




		}
		/*入孵渠道*/
		function linkRate(){
			$where=array();
			if(session('incubator_id')){
				$where['incubator_id']=session('incubator_id');
				$wheres['r.incubator_id']=session('incubator_id');
			}
			$incubator_id = $this->request->param('incubator_id',0);
			if ($incubator_id) {
				$where['incubator_id'] = $incubator_id;
				$wheres['r.incubator_id'] = $incubator_id;
				//$this->assign('incubator_id',$incubator_id);
				// $wheres['create_time'] = array('lt',$etime);
			}
			$stime = $this->request->param('start_time');
			$etime = $this->request->param('end_time');
			if ($stime) {
				$where['create_time'] = array('gt',$stime);
				$wheres['create_time'] = array('gt',$stime);
			}
			if ($etime) {
				$where['create_time'] = array('lt',$etime);
				$wheres['create_time'] = array('lt',$etime);
			}
			$stages=db('customer')->field('other_link')->where('status',1)->where($where)->select();
			// echo db('customer')->getLastSql();
			// exit;
			$arr=array();
			foreach ($stages as $key => $value) {
				if(empty($arr[$value['other_link']]['count'])){
					$arr[$value['other_link']]['count']=1;
					// switch ($value['other_link']) {
					// 	case 0:
					// 	$arr[$value['other_link']]['name']='暂无';
					// 	break;
					// 	case 1:
					// 	$arr[$value['other_link']]['name']='电话';
					// 	break;
					// 	case 2:
					// 	$arr[$value['other_link']]['name']='来访';
					// 	break;
					// 	case 3:
					// 	$arr[$value['other_link']]['name']='熟人介绍';
					// 	break;
					// 	case 4:
					// 	$arr[$value['other_link']]['name']='其他';
					// 	break;
					// 	default:
					// 		$arr[$value['other_link']]['name']='未跟进';
					// 		break;
					// }
					$arr[$value['other_link']]['name']=get_cate_name(11,$value['other_link']);
					
				}else{
					$arr[$value['other_link']]['count']++;
				}
				
	      	}
	      	$sum='';
	      	foreach ($arr as $k => $v) {
	      		$sum+=$v['count'];
	      	}
	      	foreach ($arr as $k1 => $v1) {
	      		$arr[$k1]['name']=$v1['name']. '('.round($v1['count']/$sum*100,2).'%)' ;
	      	}

	     return json($arr);
		}
		/*退租原因*/
		function lostRent(){
			$where=array();
			if(session('incubator_id')){
				$where['incubator_id']=session('incubator_id');
				$wheres['r.incubator_id']=session('incubator_id');
			}
			$incubator_id = $this->request->param('incubator_id',0);
			if ($incubator_id) {
				$where['incubator_id'] = $incubator_id;
				$wheres['r.incubator_id'] = $incubator_id;
				//$this->assign('incubator_id',$incubator_id);
				// $wheres['create_time'] = array('lt',$etime);
			}
			$stime = $this->request->param('start_time');
			$etime = $this->request->param('end_time');
			if ($stime) {
				$where['create_time'] = array('gt',$stime);
				$wheres['create_time'] = array('gt',$stime);
			}
			if ($etime) {
				$where['create_time'] = array('lt',$etime);
				$wheres['create_time'] = array('lt',$etime);
			}
			$stages=db('spaceOrder')->field('lost_rent')->where('lease_status',1)->where($where)->select();
			// echo db('spaceOrder')->getLastSql();
			// exit;
			$arr=array();
			foreach ($stages as $key => $value) {
				if(empty($arr[$value['lost_rent']]['count'])){
					$arr[$value['lost_rent']]['count']=1;
					switch ($value['lost_rent']) {
						case 0:
						$arr[$value['lost_rent']]['name']='暂无';
						break;
						case 1:
						$arr[$value['lost_rent']]['name']='孵化企业';
						break;
						case 2:
						$arr[$value['lost_rent']]['name']='价格原因';
						break;
						case 3:
						$arr[$value['lost_rent']]['name']='服务配套原因';
						break;
						case 4:
						$arr[$value['lost_rent']]['name']='缺失资源';
						break;
						case 5:
						$arr[$value['lost_rent']]['name']='其他原因';
						break;
						default:
						$arr[$value['lost_rent']]['name']='其他原因';
						break;
					}
					
				}else{
					$arr[$value['lost_rent']]['count']++;
				}
				
			}
			$sum='';
			foreach ($arr as $k => $v) {
				$sum+=$v['count'];
			}
			foreach ($arr as $k1 => $v1) {
				$arr[$k1]['name']=$v1['name']. '('.round($v1['count']/$sum*100,2).'%)' ;
			}
			return json($arr);
		}
		/*月退组数*/
		function monthLost(){
			$stime='';
			$etime='';	
			$where=array();
			if(session('incubator_id')){
				$where['incubator_id']=session('incubator_id');
				$wheres['r.incubator_id']=session('incubator_id');
			}
			$incubator_id = $this->request->param('incubator_id',0);
			if ($incubator_id) {
				$where['incubator_id'] = $incubator_id;
				$wheres['r.incubator_id'] = $incubator_id;
				//$this->assign('incubator_id',$incubator_id);
				// $wheres['create_time'] = array('lt',$etime);
			}
			$stimes = $this->request->param('start_time');
			$etimes = $this->request->param('end_time');
			// echo $stimes;
			// echo $etimes;

			if($stimes){
				$stime=$stimes;
			}
			if($etimes){
				$etime=$etimes;
			}

			if($stime && $etime){
				$syear=date("Y",strtotime($stime));
				$smonth=date("m",strtotime($stime));
				$emonth=date("m",strtotime($etime));
				$eyear=date("Y",strtotime($etime));
				$dis=ceil(between_days($stime,$etime));
				$num=ceil($dis/30);
				$year=$eyear;
				$months=$emonth;
				
			}
			elseif (!$stime && $etime) {
				$emonth=date("m",strtotime($etime));
				$eyear=date("Y",strtotime($etime));
				$year=$eyear;
				$months=$emonth;
				$num=10;
			}
			elseif($stime && !$etime){
				$smonth=date("m",strtotime($stime));
				$syear=date("Y",strtotime($stime));
				$now=time();
				$nmonth=date("m",$now);
				$nyear=date("Y",$now);
				$etime=date("Y-m-d H:i:s",$now);
				$emonth=date("m",strtotime($etime));
				$eyear=date("Y",strtotime($etime));	
				$dis=ceil(between_days($stime,$etime));
				$num=ceil($dis/30);
				$year=$eyear;
				$months=$emonth;
				
			}else{
				$year=date("Y");
				$months=date("m");
			//exit;
				$num=10;
			}
			// if(session('incubator_id')){
			// 	$where['incubator_id']=session('incubator_id');
			// 	$wheres['r.incubator_id']=session('incubator_id');
			// }
			// $stime = $this->request->param('start_time');
			// $etime = $this->request->param('end_time');
			// $sm=date('m',strtotime($stime));
			// $em=date('m',strtotime($etime));
			// // $now=time();	
			
			// if($stime && $etime){
			// 	$msum=$em-$sm+1;	
			// }
			// if($stime && !$etime){
			// 	if($sm>$now){
			// 		return;
			// 	}else{
			// 		// $mnow=date('m',$now);
			// 		$msum=($now-$sm)/(30*24*60*60)+1;
			// 	}	
			// }
			// if(!$stime && $etime){
			// 	if($em<$now){
			// 		return;
			// 	}else{
			// 		$mnow=date('m',$now);
			// 		$msum=$mnow-$sm+1;
			// 	}	
			// }

			
			// if ($stime) {
			// 	$where['create_time'] = array('gt',$stime);
			// 	$wheres['create_time'] = array('gt',$stime);
			// }
			// if ($etime) {
			// 	$where['create_time'] = array('lt',$etime);
			// 	$wheres['create_time'] = array('lt',$etime);
			// }
			// $year=date("Y");
			// $months=date("m");
			// $num=10;	
			//exit;
			for ($i=0; $i <$num ; $i++) { 

				$month=$months-$i;
				if($month<=0){
					$year=$year-1;
					$month=12;
					$time[]=$year.'-'.$month.'-1 00:00:00';
				}else{
					$time[]=$year.'-'.$month.'-1 00:00:00';
				}
			}
			foreach ($time as $key => $time) {
				$condition['lost_time']=array('gt',$time);
				$condition['lost_time ']=array('lt',date("Y-m-d",strtotime("+1 month",strtotime($time))));
		    	 
				$lost_num=db('spaceOrder')->field('lost_time')->where('lease_status',1)->where($condition)->where($where)->count();
				//echo db('spaceOrder')->getLastSql();
			//exit;
				$month=$time;
				$rate=$lost_num;
				$return[$key]['month']=explode('-', $month)[0].'-'.explode('-', $month)[1];
				$return[$key]['count']=$rate;

		    }
			// var_dump($time);
			// exit;
			// $lost_num=db('spaceOrder')->field('lost_time')->where('lease_status',1)->select();
			// foreach ($lost_num as $key => $value) {
			// 	if($value['lost_time']){
			// 		$time=explode('-', $value['lost_time']);
			// 		$k=$time[0].'-'.$time[1];
			// 		if(empty($lost[$k]['count'])){
			// 			$lost[$k]['count']=1;
			// 			$lost[$k]['month']=$time[1];
			// 		}else{
			// 			$lost[$k]['count']++;
			// 		}
			// 	}

			// }
			return json(array_reverse($return));
		}
		/*园区空置率*/
		function parkRate(){
			$etime='';
			$stime='';
			// if('2018-12-1 00:00:00'>'2017-09-1 00:00:00'){
			// 	echo 'axiba';
			// 	exit;

			// }
			$where1=array();
			$where2=array();
			if(session('incubator_id')){
				//$where['incubator_id']=session('incubator_id');
				$where1['incubator_id']=session('incubator_id');
				$where2['o.incubator_id']=session('incubator_id');
			}
			$incubator_id = $this->request->param('incubator_id',0);
			if ($incubator_id) {
				$where1['incubator_id'] = $incubator_id;
				$where2['o.incubator_id'] = $incubator_id;
				//$this->assign('incubator_id',$incubator_id);
				// $wheres['create_time'] = array('lt',$etime);
			}
			$stimes = $this->request->param('start_time');
			$etimes = $this->request->param('end_time');
			if($stimes){
				$stime=$stimes;
			}
			if($etimes){
				$etime=$etimes;
			}
			if($stime && $etime){
				$syear=date("Y",strtotime($stime));
				$smonth=date("m",strtotime($stime));
				$emonth=date("m",strtotime($etime));
				$eyear=date("Y",strtotime($etime));
				$dis=ceil(between_days($stime,$etime));
				$num=ceil($dis/30);
				$year=$eyear;
				$months=$emonth;
			}
			elseif (!$stime && $etime) {
				$emonth=date("m",strtotime($etime));
				$eyear=date("Y",strtotime($etime));
				$year=$eyear;
				$months=$emonth;
				$num=10;
			}
			elseif($stime && !$etime){
				$smonth=date("m",strtotime($stime));
				$syear=date("Y",strtotime($stime));
				$now=time();
				$nmonth=date("m",$now);
				$nyear=date("Y",$now);
				$etime=date("Y-m-d H:i:s",$now);
				$emonth=date("m",strtotime($etime));
				$eyear=date("Y",strtotime($etime));	
				$dis=ceil(between_days($stime,$etime));
				$num=ceil($dis/30);
				$year=$eyear;
				$months=$emonth;
				
			}else{
				$year=date("Y");
				$months=date("m");
			//exit;
				$num=10;
			}
			// if ($stime) {
			// 	$where['create_time'] = array('gt',$stime);
			// 	$wheres['create_time'] = array('gt',$stime);
			// }
			// if ($etime) {
			// 	$where['create_time'] = array('lt',$etime);
			// 	$wheres['create_time'] = array('lt',$etime);
			// }




			$type=$param=$this->request->param('type',1);

			$sit=$param=$this->request->param('sit');;
			if(!$type){
				return;
			}
			if($type==2 && $sit==2){
				$where['incubator_type']=2;
				$where['type']=2;
				
			}else{
				$where['incubator_type']=$type;
				$where['type']=1;
			}
			
		    for ($i=0; $i <$num ; $i++) { 

		    	$month=$months-$i;
		    	if($month<=0){
		    		$year=$year-1;
		    		$month=12;
		    		$time[]=$year.'-'.$month.'-1 00:00:00';
		    	}else{
		    		$time[]=$year.'-'.$month.'-1 00:00:00';
		    	}
		    }
		   // echo $time;
		  // db('spaceOrder')->alias('o')->join('station s' ,'o.space_id=s.id' )->where(array('s.incubatory_type'=>1,'start_time <'=>$yim))->count();
		    //exit;
		    // $condition['start_time ']=array('lt',$time);
		    // $condition['end_time ']=array('gt',$time);
		    $park_num=db('station')->where($where)->where($where1)->count();
		  //  echo $park_num;
		  //  exit;
		   // echo db('station')->getLastSql();
		     //exit;
		    // echo $park_num;
		    // echo 2222;
		    if(!$park_num){
		    	// echo db('station')->getLastSql();
		    	// exit;
		    	return;
		    }
		    // echo db('station')->getLastSql();
		    // exit;
		    //echo $park_num;
		    foreach ($time as $key => $time) {
		    	 $condition['_string']='(start_time>="'.$time.'" and  end_time<="'.date("Y-m-d",strtotime("+1 month",strtotime($time))).'")   or (start_time<="'.$time.'" and  end_time>="'.date("Y-m-d",strtotime("+1 month",strtotime($time))).'") or (start_time>="'.$time.'" and start_time<="'.date("Y-m-d",strtotime("+1 month",strtotime($time))).'" and  end_time>="'.date("Y-m-d",strtotime("+1 month",strtotime($time))).'") or (start_time<="'.$time.'" and end_time>="'.$time.'" and  end_time<="'.date("Y-m-d",strtotime("+1 month",strtotime($time))).'")';
		    	 $lease_status['lease_status']=array('lt',1);
		    	 $order_park_num=db('spaceOrder')->alias('o')->join('station s' ,'o.space_id=s.id' )->where($where)->where($condition['_string'])->where($where2)->where($lease_status)->count();
		    	 // echo db('spaceOrder')->getLastSql();
		    	  // exit;
		    	// echo $park_num;
		    	// echo '@@@@';
		    	 $stay_num=abs($park_num-$order_park_num);
		    	//echo $stay_num;
		    	 $month=$time;
		    	 $rate=round($stay_num/$park_num,2);
		    	 $return[$key]['month']=explode('-', $month)[0].'-'.explode('-', $month)[1];
		    	 $return[$key]['rate']=$rate;

		    }
		 //   exit;
		    return json(array_reverse($return)); 
		}
      





}


